import requests


class RequestsUtils:
    def request_res(self, method, url, data, headers):
        data = eval(data)
        headers = eval(headers)

        if method.upper() == "POST":
            return requests.post(url, json=data, headers=headers)
        elif method.upper() == "GET":
            return requests.get(url, params=data, headers=headers)
        else:
            print("请求方式错误")

if __name__ == '__main__':
    import json
    data = {
        "viewId": "b4110e02-b4d3-44a7-ab53-0562479c24c3",
        "canvas": {"x": -3592, "y": -256},
        "param":
            {
                "objectCode": "Product",
                "objectName": {"en": "Product", "zh-cn": "产品"},
                "businessMainKeyCode": "productNo",
                "businessMainKeyName": {"en": "productNo", "zh-cn": "产品编号"},
                "generateBusinessKeyValType": "AUTOINCREMENT",
                "generateBusinessKeyValHeader": "info_"
            },
        "templateType": "BUSINESS_DATA"
    }
    url = "https://alpha.deepfos.com/deepfos-server/deep-model-server/object/template/instance"
    headers = {
        'Content-Type': 'application/json',
        'accept-language': 'zh-CN,zh;q=0.9',
        'app': 'zauoyn040',
        'content-type': 'application/json;charset=UTF-8',
        'cookie': 'v3test_deepfos_users=%7B%22color%22%3A%226%22%2C%22email%22%3A%22wanyu.jiang%40proinnova.com.cn%22%2C%22invitationActivation%22%3Atrue%2C%22nickName%22%3A%22%E5%A7%9C%E6%99%9A%E7%8E%89%22%2C%22nickname%22%3A%22%E5%A7%9C%E6%99%9A%E7%8E%89%22%2C%22token%22%3A%22D4822E958B0AE622B5E70DFBAA70A9DED3CDB4A158943A1DD1B3B3542C1CB865%22%2C%22tokenKey%22%3A%22v3test_deepfos_token%22%2C%22type%22%3A1%2C%22userId%22%3A%22392abb68-8f20-4bb3-9e7c-d5e3b2a56ff0%22%2C%22username%22%3A%22jiangwanyu%22%7D; v3test_deepfos_token=D4822E958B0AE622B5E70DFBAA70A9DED3CDB4A158943A1DD1B3B3542C1CB865; cloud_deepfos_users=%7B%22color%22%3A%226%22%2C%22email%22%3A%22wanyu.jiang%40proinnova.com.cn%22%2C%22invitationActivation%22%3Atrue%2C%22nickName%22%3A%22%E5%A7%9C%E6%99%9A%E7%8E%89%22%2C%22nickname%22%3A%22%E5%A7%9C%E6%99%9A%E7%8E%89%22%2C%22token%22%3A%22D4822E958B0AE622B5E70DFBAA70A9DE34D90D468D14CFB37B7664BD9CBF4017%22%2C%22tokenKey%22%3A%22cloud_deepfos_token%22%2C%22type%22%3A1%2C%22userId%22%3A%228e3ce009-d6ee-4fe4-9759-1fcc5146fbbe%22%2C%22username%22%3A%22jiangwanyu%22%7D; cloud_deepfos_token=D4822E958B0AE622B5E70DFBAA70A9DE34D90D468D14CFB37B7664BD9CBF4017; alpha_deepfos_users=%7B%22color%22%3A%226%22%2C%22email%22%3A%22wanyu.jiang%40proinnova.com.cn%22%2C%22invitationActivation%22%3Atrue%2C%22nickName%22%3A%22%E5%A7%9C%E6%99%9A%E7%8E%89%22%2C%22nickname%22%3A%22%E5%A7%9C%E6%99%9A%E7%8E%89%22%2C%22token%22%3A%222E1F89D1221272342BAD6C41351A32B435CBBB3B14823B2D4CA9BD66C99DB9BC%22%2C%22tokenKey%22%3A%22alpha_deepfos_token%22%2C%22type%22%3A1%2C%22userId%22%3A%228e3ce009-d6ee-4fe4-9759-1fcc5146fbbe%22%2C%22username%22%3A%22jiangwanyu%22%7D; alpha_deepfos_token=2E1F89D1221272342BAD6C41351A32B435CBBB3B14823B2D4CA9BD66C99DB9BC',
        'language': 'zh-cn',
        'space': 'zauoyn'
    }
    a = RequestsUtils().request_res(method="post", url=url, data=data, headers=headers)
    a = json.loads(a.text)
    print(a['code'])
    print(a['message'])
    print(a['status'])
    print(a['data'])
